package com.base.api.cdr;

import com.base.api.pms.PmsPublicSqlQuery;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Component;

import java.text.MessageFormat;
import java.util.HashMap;
import java.util.Map;

/**
 * @author wnhuang
 * @Package com.base.api.cdr
 * @date 2020-12-19 23:20
 */
@Component
public class PersonalSqlIndexQuery extends PmsPublicSqlQuery {

    @Override
    public Map<String, Object> beforReturn(Map<String, Object> map) {
        Map<String,Object> map1 = new HashMap<>();
        map1.put("PersonalInfo",map);
        return map1;
    }

    @Override
    public String splicSql(String sql, Map<String, Object> param){
        StringBuilder param1 = new StringBuilder();
        if(param != null){
            if(param.get("patientId") != null && !StringUtils.isBlank((String) (param.get("patientId")))){
                param1.append(" and P.PATIENT_ID = '" + param.get("patientId") + "'");
            }
            if(param.get("visitNumber") != null && !StringUtils.isBlank((String) (param.get("visitNumber")))){
                param1.append(" and A.PAI_VISIT_ID = '" + param.get("visitNumber") + "'");
            }
            if(param.get("OporIpVn") != null && !StringUtils.isBlank((String) (param.get("OporIpVn")))){
                param1.append(" and A.PAI_VISIT_ID = '" + param.get("OporIpVn") + "'");
            }
        }
        return MessageFormat.format(sql.replace("'","''"), param1.toString());
    };
}
